<%-- 
    Document   : order
    Created on : Jul 9, 2011, 3:30:49 PM
    Author     : ThanhToan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="dao.OrderDAO" %>
<%@ page import="model.OrderModel" %>
<%@ page import="common.Constant" %>
<%@ page import="java.util.ArrayList"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Order Page</title>
    </head>
    <body>
        <div id="main_container">
		<!-- S HEAD CONTENT -->
			<jsp:include page="block/header.jsp" />
		<!-- E HEAD CONTENT -->

		<!-- S Top Menu -->
			<jsp:include page="block/top_menu.jsp" />
		<!-- E Top Menu -->

                <!-- S Navigation -->
			<jsp:include page="block/navigation.jsp" />
		<!-- E Navigation -->

                <!-- S Left Menu -->
			<jsp:include page="block/left_menu.jsp" />
		<!-- E Left Menu -->
                
                <c:choose>
                    <c:when test = "${sessionScope.role eq 'Dealer'}">
                            <c:set var="orderList" value = '<%= OrderDAO.getAllOrder() %>' scope="session"></c:set>
                    </c:when>
                    <c:otherwise>
                            <c:set var="orderList" value = '<%= OrderDAO.getAllOrderByUserID((String)session.getAttribute("userID")) %>' scope="session"></c:set>
                    </c:otherwise>
                </c:choose>

                <c:set var="integer" value="1"></c:set>
                
		<!-- S Body Content -->
                <div class="center_content">
                    <form action="OrderController" method="post" id="order" name="order">
                        <c:if test="${not empty param.msg and param.msg eq 'update'}">
                            <b class="msg"> Review success! </b>
                        </c:if>
                        <table cellpadding="0" cellspacing="0" border="0" style="background: transparent" align="center">
                            <tr>
                                <td colspan="8" align="center">
                                    <h1>Order List</h1>
                                </td>
                            </tr>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="2" style="background: transparent" align="center">
                            <tr>
                                <td align="center" width="20px">No.</td>
                                <th bgcolor= '#186fb2' style="width: 130px"><div class = "div_txtintable1">Date</div></th>
                                <th bgcolor= '#186fb2' ><div class = "div_txtintable1">Customer<br/>(Firstname.Lastname)</div></th>
                                <th bgcolor= '#186fb2'><div class = "div_txtintable1">Status</div></th>
                                <th bgcolor= '#186fb2'><div class = "div_txtintable1">Approved By</div></th>
                                <th bgcolor= '#186fb2' style="width: 130px"><div class = "div_txtintable1">LastUpdate</div></th>
                                <th bgcolor= '#186fb2'><div class = "div_txtintable1">Reject Reason</div></th>
                                <c:if test="${sessionScope.role eq 'Dealer'}">
                                    <c:if test="${objOrder.status eq 0 or objOrder.status eq 2}">
                                        <th bgcolor= '#186fb2'><div class = "div_txtintable1"></div></th>
                                    </c:if>
                                </c:if>
                            </tr>
                            <c:forEach var="objOrder" items="${orderList}">
                                <tr>
                                    <td align="center" style="height: 25px">${integer}</td>
                                    <td><a href="orderDetails.jsp?orderID=${objOrder.id}&status=${objOrder.status}">${objOrder.date}</a></td>
                                    <td align="center">${objOrder.cusName}</td>
                                    <td width="50px" align="center">
                                        <c:choose>
                                            <c:when test = "${objOrder.status eq 0}">
                                                    New
                                            </c:when>
                                            <c:when test = "${objOrder.status eq 1}">
                                                    Approved
                                            </c:when>
                                            <c:when test = "${objOrder.status eq 2}">
                                                    Rejected
                                            </c:when>
                                            <c:otherwise>
                                                    Close
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td align="center">${objOrder.dealerName}</td>
                                    <td>${objOrder.lastUpdate}</td>
                                    <td>
                                        <textarea rows="3" cols="10" id="txtaReason${integer}" name="txtaReason${integer}"
                                                  <c:if test="${objOrder.status ne 0}">readonly</c:if>
                                              >${objOrder.rejectReason}</textarea>
                                    </td>
                                    <c:if test="${sessionScope.role eq 'Dealer'}">
                                        <c:if test="${objOrder.status eq 0 or objOrder.status eq 2}">
                                            <td style="width: 75px">
                                                <c:if test="${objOrder.status eq 0 or objOrder.status eq 2}">
                                                    <a href="OrderController?review=yes&action1=approve&orderID=${objOrder.id}"> <img src="images/approve.png" alt="Approve"/> </a>
                                                </c:if>
                                                <c:if test="${objOrder.status eq 0}">
                                                    <br/><a href="OrderController?review=yes&action1=reject&orderID=${objOrder.id}"> <img src="images/reject.png" alt="Reject"/> </a>
                                                </c:if>
                                            </td>
                                        </c:if>
                                    </c:if>
                                </tr>
                                <c:set var="integer" value="${integer+1}"></c:set>
                            </c:forEach>
                        </table>

                    </form>
                </div>
		<!-- E Body Content -->

                <!-- S Footer -->
			<jsp:include page="block/footer.jsp" />
		<!-- E Footer -->
	</div>
    </body>
</html>
